setClass("R2DimChooser",contains="LLEDimChooser",
		prototype=prototype(
				.description="R2 DimChooser"
		)
)
#methods

setMethod("chooseBest",
		signature=c("R2DimChooser","LLEReducer"),
		definition= function(.Object,reducer,...){
			
			#initial computations
			dims <- dim(reducer@.tmpData)
			rows <- dims[1] #objects
			cols <- dims[2] #dimensions
			checkedDims <- min(rows -1,cols)
			
			scores <- unlist(lapply(1:checkedDims,FUN=function(cDim){
								redSet <-as.matrix(find_coords(reducer@.weights$wgts,reducer@.knn,rows,cols,cDim))
								scoreSet(.Object,reducer,redSet)
							}))
			
			return(as.integer(which.max(scores)))
		}
)


setMethod("scoreSet",
		signature=c("R2DimChooser","LLEReducer"),
		definition= function(.Object,reducer,outSet2Score,...){
			
			#numeric vectors
			dX <- as.matrix(dist(reducer@.tmpData))[reducer@.knn]
			dY <- as.matrix(dist(outSet2Score))[reducer@.knn]
			
			vecLength<- length(which(reducer@.knn==TRUE))
			mdX <- mean(dX)
			mdY <- mean(dY)
			
			numerator <- sum(dX*dY) - vecLength*mdX*mdY
			denominator <-{sum(dX*dX) - vecLength*(mdX^2)}*{sum(dY*dY) - vecLength*(mdY^2) }
			
			return(numerator/denominator)
		}
)